@var head = {
	<link href="${request.contextPath}/lib/ztree/zTreeStyle.css" rel="stylesheet" type="text/css" />
	<title>设置权限</title>
@};
@var content = {
	<div class="pd-5" style="height:100%">
		<ul id="actionTree" class="ztree">
			
		</ul>
		<div class="cl pd-5 mt-20"> 
			<span class="l">
				<a href="javascript:;" onclick="selActions();" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 设置权限</a>
			</span> 
		</div>
		<input type="hidden" id="ids" name="ids">
	</div>
@};
@var js = {
	<script type="text/javascript" src="${request.contextPath}/lib/ztree/jquery.ztree.all-3.5.min.js"></script> 
	<script>
		var zNodes = [
	             	{id : '0', pId : 0, name : '权限管理', isParent : true, open : true, checked : true, nocheck : true}
        ];
  		var treeSetting = {
			check: {
				chkboxType : {"Y" : "ps", "N" : "ps"},
				enable: true
			},
  			view : {
  				dblClickExpand : false
  			},
  			async : {
  				enable : true,
  				url : "${request.contextPath}/res/actionchilds.html?rid=${resId}&t=" + Math.random(),
  				autoParam : ["id=id"],
  				dataFilter: ajaxDataFilter
  			},
  			callback : {
  				onCheck : onActionTreeCheck
  			}
  		};
		$(document).ready(function () {
			var actionTree = $.fn.zTree.init($("#actionTree"), treeSetting, zNodes);
			expandFirstNode(actionTree);
		});
		function expandFirstNode(actionTree){
			var nodes = actionTree.getNodes();  
			actionTree.expandNode(nodes[0], true);
		}
		function onActionTreeCheck(e, treeId, treeNode) {
			var actionTree = $.fn.zTree.getZTreeObj(treeId);
			var nodes = actionTree.getCheckedNodes(true);
			var ids = "";
			var names = "";
			for (var i = 0, l = nodes.length; i < l; i++) {
				ids += nodes[i].id + ",";
				names += nodes[i].name + ",";
			}
			if (ids.length > 0)
				ids = ids.substring(0, ids.length - 1);
			if (names.length > 0)
				names = names.substring(0, names.length - 1);
			$("#ids").val(ids);
			//alert($("#ids").val());
		}
		function ajaxDataFilter(treeId, parentNode, responseData) {
		    return responseData.data;
		}
		function selActions(){
			var options = {
					url : "${request.contextPath}/res/selactions.html?rid=${resId}",
					data : {ids : $("#ids").val()},
					error : function(e){
			        	layer.msg('请求错误');
			        },
			        success : function(e){
			        	if(e.code == 200){
			        		layer.msg('操作成功');
			        	}
			        	else{
			        		layer.msg('操作失败');
			        	}
			        }
			};
			commmonAjax(options);
			return false;
		}
	</script>
@};
@include("/layout/layout.html",{head:head,content:content,js:js}){}